package com.px.user.entity;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.px.user.model.ActionModel;
import com.px.user.model.PagingModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.math.BigDecimal;
import java.sql.Timestamp;

@Data
@SuperBuilder
@NoArgsConstructor
@Entity(name = "red_pack_grab")
@EqualsAndHashCode(callSuper = true)
@org.hibernate.annotations.Table(appliesTo = "red_pack_grab", comment = "抢红包记录表")
public class RedPackGrab extends PagingModel {

    @Id
    @ApiModelProperty(value = "主键", hidden = true)
    @NotNull(groups = {ActionModel.Update.class})
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Null(groups = {ActionModel.Insert.class}, message = "删除id字段")
    @Column(unique = true, nullable = false, columnDefinition = "bigint comment '主键'")
    private Long id;

    @NotNull(groups = {ActionModel.Insert.class})
    @ApiModelProperty(value = "红包ID", example = "2")
    @Column(columnDefinition = "bigint comment '红包ID'")
    private Long redPackId;

    @ApiModelProperty(value = "抢包人ID", example = "2")
    @Column(columnDefinition = "bigint comment '抢包人ID'")
    private Long toUserId;

    @ApiModelProperty(value = "金额", example = "@不提交")
    @Column(columnDefinition = "decimal(12,2) comment '抢包金额'")
    @Null(groups = {ActionModel.Insert.class}, message = "删除money字段")
    private BigDecimal money;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "创建时间", hidden = true)
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间'", insertable = false, updatable = false)
    private Timestamp createTime;

    /**
     * 扩展字段
     */
    @Transient
    @NotNull(groups = {ActionModel.Insert.class})
    @ApiModelProperty(value = "发包人ID", example = "2")
    private Long fromUserId;

    @Transient
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @ApiModelProperty(value = "发包人昵称", example = "@不提交")
    private String fromNickname;

    @Transient
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @ApiModelProperty(value = "收包人昵称", example = "@不提交")
    private String toNickname;

    @Transient
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @ApiModelProperty(value = "是机器人?: 1#是,0#否", example = "@不提交")
    private Integer isRobot;
}
